package com.gzwh.v1.sysapi.conntroller.system;


import com.gzwh.v1.sysapi.dao.SysProvinceMapper;
import com.gzwh.v1.sysapi.entity.system.ProvinceEntity;
import com.gzwh.v1.sysapi.server.impl.RedisServiceImpl;
import com.gzwh.v1.sysapi.utils.ReturnUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.BoundListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.ui.ModelMap;

import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.TimeUnit;

import static com.gzwh.v1.sysapi.utils.DateUtil.getSysTime;

/**
 * 系统相应工具，
 * 1、info为系统探针
 * 2、province 省份获取
 *
 * 时间：2019-07-13
 */
@RestController
@RequestMapping("/system")
public class SystemInfo {


    @Autowired
    private RedisTemplate redisTemplate = null;

    @Autowired
    private StringRedisTemplate stringRedisTemplate = null;

    @Autowired
    private SysProvinceMapper sysProvinceMapper;

    @RequestMapping(value = "/info", method = RequestMethod.GET)
    public ModelMap info() {
        stringRedisTemplate.opsForValue().set("123123", "124124124", 5, TimeUnit.MINUTES);
        System.out.println(stringRedisTemplate.opsForValue().get("int"));
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("title", "hello world!");
        hashMap.put("content", "欢迎访问本系统");
        hashMap.put("version", "1.0.100");
        hashMap.put("date", getSysTime());
        return ReturnUtil.Success(null, hashMap);
    }
    //根据上一级id编号，获取省份或城市
    //上一级id为0，标识省份，后续由上一级id进行获取

    @RequestMapping("/province")
    public ModelMap getProvince(@RequestParam("Uid") String Uid) {
        List<ProvinceEntity> provinceEntityList = sysProvinceMapper.getProvinceByUpid(Uid);
        List<Object> list = new ArrayList<>();
        for (ProvinceEntity goo : provinceEntityList) {
            HashMap<String, Object> hashMap = new HashMap<>();
            hashMap.put("id", goo.getId());
            hashMap.put("name", goo.getName());
            hashMap.put("level", goo.getLevel());
            list.add(hashMap);
        }
        return ReturnUtil.Success(null, list);
    }




}
